package leecode

func twoOutOfThree(nums1 []int, nums2 []int, nums3 []int) (result []int) {
	hashNum1, hashNum2, hashNum3 := make(map[int]int), make(map[int]int), make(map[int]int)
	for i := 0; i < len(nums1); i++ {
		hashNum1[nums1[i]]++
	}
	for i := 0; i < len(nums2); i++ {
		hashNum2[nums2[i]]++
		if _, ok := hashNum1[nums2[i]]; ok && hashNum2[nums2[i]] <= 1 {
			result = append(result, nums2[i])
		}
	}
	for i := 0; i < len(nums3); i++ {
		hashNum3[nums3[i]]++
		_, ok1 := hashNum1[nums3[i]]
		_, ok2 := hashNum2[nums3[i]]
		if ok1 && ok2 {
			continue
		} else if (ok1 || ok2) && hashNum3[nums3[i]] <= 1 {
			result = append(result, nums3[i])
		}
	}
	return
}
